import axios from "../../ajax/ajax";
import React, { Component } from "react";

class ajax extends Component {
  constructor(props) {
    super(props);
    this.state = {
      username: "",
      lastGistUrl: "",
    };
  }
  //  生命周期
  componentDidMount() {
    axios({
      url: 'https://api.github.com/search/repositories?q=javascript&sort=stars',
    })
      .then((result) => {
        console.log(result, "数据--------------");
        var lastGist = result.data.items[0];
        this.setState({
          username: lastGist.owner.login,
          lastGistUrl: lastGist.html_url,
        });
      })
      .catch((err) => {
        console.log(err, "err");
      });
  }
  render() {
   console.log(this.props.source,'===this.props.source')
    return (
      <div>
        {this.state.username}'s last gist is{" "}
        <a href={this.state.lastGistUrl}>here</a>.
      </div>
    );
  }
}
export default ajax;
